package ai.people.platform.dict.config;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import org.springframework.beans.BeansException;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 说明
 *
 * @author zhenglin
 * @since 2022/3/14
 */
@Component
public class MybatisScanClassPathConfiguration extends ConfigurationPropertiesBindingPostProcessor {


    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (MybatisPlusProperties.class.isAssignableFrom(bean.getClass())){
            MybatisPlusProperties mybatisPlusProperties = ((MybatisPlusProperties) bean);
            String[] mapperLocations = mybatisPlusProperties.getMapperLocations();
            String[] finalArr = new String[mapperLocations.length + 1];
            System.arraycopy(mapperLocations, 0, finalArr, 0,
                    mapperLocations.length);
            finalArr[finalArr.length-1] = "classpath*:mappers/*.xml";
            mybatisPlusProperties.setMapperLocations(finalArr);
        }
        return super.postProcessAfterInitialization(bean, beanName);
    }
}
